From f8de6179af617b48213384f6de6b15364fb2d687 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Sat, 4 Mar 2006 19:10:56 +0100 Subject: [PATCH] Added a 'state' field to the xenbus_device structure, which caches the state at the local end of the xenbus connection (i.e. that value that is passed through xenbus_switch_state). This means that xenbus_probe can wait for all the boot devices to become ready without having to hurt the store. Also, fix this probing -- previously, the wrong value was being returned by all_devices_ready_, so this polling would only have waited for one device. Signed-off-by: Ewan Mellor --- .../drivers/xen/xenbus/xenbus_client.c | 16 +++++++++++----- .../drivers/xen/xenbus/xenbus_probe.c | 7 ++----- linux-2.6-xen-sparse/include/xen/xenbus.h | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c index 444f0e9f0d..d8d0b9e71d 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c @@ -95,18 +95,25 @@ int xenbus_switch_state(struct xenbus_device *dev, */ int current_state; + int err; + + if (state == dev->state) + return 0; - int err = xenbus_scanf(xbt, dev->nodename, "state", "%d", + err = xenbus_scanf(xbt, dev->nodename, "state", "%d", ¤t_state); - if ((err == 1 && (XenbusState)current_state == state) || - err == -ENOENT) + if (err != 1) return 0; err = xenbus_printf(xbt, dev->nodename, "state", "%d", state); if (err) { - xenbus_dev_fatal(dev, err, "writing new state"); + if (state != XenbusStateClosing) /* Avoid looping */ + xenbus_dev_fatal(dev, err, "writing new state"); return err; } + + dev->state = state; + return 0; } EXPORT_SYMBOL(xenbus_switch_state); @@ -138,7 +145,6 @@ void _dev_error(struct xenbus_device *dev, int err, const char *fmt, ret = vsnprintf(printf_buffer+len, PRINTF_BUFFER_SIZE-len, fmt, ap); BUG_ON(len + ret > PRINTF_BUFFER_SIZE-1); - dev->has_error = 1; dev_err(&dev->dev, "%s\n", printf_buffer); diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c index cab6d5bec8..1bf9e54908 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c @@ -888,16 +888,13 @@ static int all_devices_ready_(struct device *dev, void *data) { struct xenbus_device *xendev = to_xenbus_device(dev); int *result = data; - int state; - int err = xenbus_scanf(XBT_NULL, xendev->nodename, "state", "%d", - &state); - if (err != 1 || state != XenbusStateConnected) { + if (xendev->state != XenbusStateConnected) { result = 0; return 1; } - return 1; + return 0; } diff --git a/linux-2.6-xen-sparse/include/xen/xenbus.h b/linux-2.6-xen-sparse/include/xen/xenbus.h index 88b7420935..5c1507b8b0 100644 --- a/linux-2.6-xen-sparse/include/xen/xenbus.h +++ b/linux-2.6-xen-sparse/include/xen/xenbus.h @@ -63,7 +63,7 @@ struct xenbus_device { int otherend_id; struct xenbus_watch otherend_watch; struct device dev; - int has_error; + XenbusState state; void *data; }; -- 2.30.2